//
//  UpdateChecklistUIService.swift
//  ezyform
//
//  Created by Moennig Q on 20/4/2022.
//  Copyright © 2022 Client.Solution Pty Ltd. All rights reserved.
//

import Foundation
class SystemInfoService {
    open class func shared() -> SystemInfoService{
        struct Static {
            static let instance : SystemInfoService = SystemInfoService()
        }
        return Static.instance
    }
    //获取installer的accredited_number，在签名中显示
    func loadMyInformation(_ successClosure:(()->Void)? = nil, faildClosure:((String,String)->Void)? = nil){
        //set block
       let viewModel = MyInformationService()
        viewModel.setBlockAfterNetwork({(result , _) -> Void in
            
            if let model = result as? MyInformationModel{
                APPConfig.loginInfo.accreditedNumber = model.accredited_number
                APPConfig.loginInfo.avatarURLStr = model.avatars.thumb_160
                Tool().setValueOfUserDefaults(model.avatars.thumb_160, key: APPConfig.LoginUserAvatarKey)
                //获取当前用户信息
                APPConfig.loginInfo.designer = model.designer
                APPConfig.loginInfo.installer = model.installer
                APPConfig.loginInfo.app_create_job = model.app_create_job
                //plumber
                APPConfig.loginInfo.plumber = model.plumber
                APPConfig.loginInfo.plumber_licenses = model.plumber_licenses
                
                UserDefaults.standard.set(model.accredited_number, forKey: model.email + "-AccreditedNumber")
                UserDefaults.standard.set(model.accredited_number, forKey: model.email + "-PlumberLicenses")
                
                /// 2024 3-2 新增
                APPConfig.loginInfo.saaNumber = model.saa_number
                UserDefaults.standard.set(model.saa_number, forKey: model.saa_number + "-SaaNumber")
            }
            successClosure?()
        }) {(code, error) -> Void in
            faildClosure?(code, error)
        }
      
        viewModel.getMyInformation()

    }
}
